//
Create a Input for typing a value
Create a button so if user type any value and then click on button then this value show below of the button
Show alert if click on button without typing any value
Show all value below of the button.
const addtask = document.getElementById('addtask');
const taskDiv = document.getElementById('task-div');
taskDiv.innerText = "No Data Found !";
function addData(){
if(addtask.value.length == 0){
alert("Enter Value");
return;
}
if (taskDiv.innerText === "No Data Found !") {
taskDiv.innerText = "";
}
var id = Math.random().toString(16).slice(2)
const taskValue= addtask.value;
addtask.value ="";
const task=document.createElement('div');
const taskName=document.createElement('p');
const deleteIcon =document.createElement('i');
deleteIcon.setAttribute("class","fa-solid fa-trash");
deleteIcon.setAttribute("onclick",`removeData("${id}")`);
task.setAttribute("id",id);
task.setAttribute("class","task");
taskName.innerHTML=taskValue;
task.append(deleteIcon,taskName);
taskDiv.appendChild(task);
}
function removeData(id){
const taskid=document.getElementById(id)
if(taskid){
taskid.remove();
}
}